package com.web.rabitmq.sender.com.web.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 发送消息服务层
 */
@Component
public class SendMsgService {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    /**
     * 发送direct消息
     * @param msg
     */
    public void sendDirect(String msg){
        System.out.println("direct消息队列即将发送的消息:"+msg);
        rabbitTemplate.convertAndSend("queue", msg);//绑定队列名queue
    }

    /**
     * 发送topic消息
     * @param msg
     */
    public void sendTopic(String msg){
        System.out.println("topic消息队列即将发送的消息:"+msg);
        rabbitTemplate.convertAndSend("coreExchange", "api.core.user", msg);
    }
}
